package com.gqj.meter.service.impl;

import com.gqj.meter.domain.MdWarningInfo;
import com.gqj.meter.mapper.MdWarningInfoMapper;
import com.gqj.meter.service.IMdWarningInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * 告警信息Service业务层处理
 *
 * @author lxq
 * @date lxq-02-10
 */
@Service
public class MdWarningInfoServiceImpl implements IMdWarningInfoService {
    @Autowired
    private MdWarningInfoMapper mdWarningInfoMapper;

    /**
     * 查询告警信息
     *
     * @param warningId 告警信息主键
     * @return 告警信息
     */
    @Override
    public MdWarningInfo selectMdWarningInfoByWarningId(Long warningId) {
        return mdWarningInfoMapper.selectMdWarningInfoByWarningId(warningId);
    }

    /**
     * 查询告警信息列表
     *
     * @param mdWarningInfo 告警信息
     * @return 告警信息
     */
    @Override
    public List<MdWarningInfo> selectMdWarningInfoList(MdWarningInfo mdWarningInfo) {
        return mdWarningInfoMapper.selectMdWarningInfoList(mdWarningInfo);
    }

    /**
     * 新增告警信息
     *
     * @param mdWarningInfo 告警信息
     * @return 结果
     */
    @Override
    public int insertMdWarningInfo(MdWarningInfo mdWarningInfo) {
        return mdWarningInfoMapper.insertMdWarningInfo(mdWarningInfo);
    }

    /**
     * 修改告警信息
     *
     * @param mdWarningInfo 告警信息
     * @return 结果
     */
    @Override
    public int updateMdWarningInfo(MdWarningInfo mdWarningInfo) {
        return mdWarningInfoMapper.updateMdWarningInfo(mdWarningInfo);
    }

    /**
     * 批量删除告警信息
     *
     * @param warningIds 需要删除的告警信息主键
     * @return 结果
     */
    @Override
    public int deleteMdWarningInfoByWarningIds(Long[] warningIds) {
        return mdWarningInfoMapper.deleteMdWarningInfoByWarningIds(warningIds);
    }

    /**
     * 删除告警信息信息
     *
     * @param warningId 告警信息主键
     * @return 结果
     */
    @Override
    public int deleteMdWarningInfoByWarningId(Long warningId) {
        return mdWarningInfoMapper.deleteMdWarningInfoByWarningId(warningId);
    }

    //统计报警数量
    @Override
    public List<Map<String, Object>> getWarningCounts() {
        List<Map<String, Object>> warningCouts = mdWarningInfoMapper.getWarningCounts();
        // 遍历结果集并将月份格式化
        for (Map<String, Object> warningCount : warningCouts) {
            String month = warningCount.get("month").toString();
            String formattedMonth = String.format("%d月", Integer.parseInt(month));
            warningCount.put("month", formattedMonth);
        }
        return warningCouts;
    }
}
